package company.meituan_F;

import java.util.*;

// 递归版本  需要使用递归解决深度优先遍历 图最好用二维数组
public class M3B {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] dict = new int[n][n];
        Map<Integer, Integer> map = new TreeMap<>();
        for (int i = 0; i < m; i++) {
            int start = sc.nextInt();
            int end = sc.nextInt();
            dict[start][end] = 1;
            dict[end][start] = 1;
            map.put(start, 0);
            map.put(end, 0);
        }
        List<TreeSet<Integer>> result = new ArrayList<>();
        for (Map.Entry<Integer, Integer> e : map.entrySet()) {
            if (e.getValue() == 0) {
                TreeSet<Integer> set = new TreeSet<>();
                result.add(set);
                dfs(e.getKey(), dict, set, map, n);
            }
        }
        System.out.println(result);
    }

    private static void dfs(int i, int[][] dict, TreeSet<Integer> set, Map<Integer, Integer> map, int n) {
        map.put(i, 1);
        set.add(i);
        for (int j = 0; j < n; j++) {
            if (dict[i][j] == 1 && map.get(j) == 0) {
                dfs(j, dict, set, map, n);
            }
        }
    }
}
